@extends('admin::layouts.master')
@section('title')
    订单列表
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-input-inline layui-show-xs-block" style="width: 300px;    ">
                                <input type="text" name="name" placeholder="优惠券名称" value="{{$arr_search['name']}}" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-show-xs-block" style="width: 300px;    ">
                                <input type="text" name="ticket_num" placeholder="优惠券券号" value="{{$arr_search['ticket_num']}}" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="pid">
                                    <option value="">优惠券类型</option>
                                    <option value="1" @if( $arr_search['pid'] == 1  ) selected="" @endif >洗车券</option>
                                    <option value="2" @if( $arr_search['pid'] == 2  ) selected="" @endif >满减券</option>
                                    <option value="3" @if( $arr_search['pid'] == 3  ) selected="" @endif >折扣券</option>
                                </select>
                            </div>

                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="type">
                                    <option value="">使用类型</option>
                                    <option value="1" @if( $arr_search['type'] == 1  ) selected="" @endif >普通商品</option>
                                    <option value="2" @if( $arr_search['type'] == 2  ) selected="" @endif >服务商品</option>
                                    <option value="3" @if( $arr_search['type'] == 3  ) selected="" @endif >保养套餐</option>
                                </select>
                            </div>

                            <div class="layui-input-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                    <i class="layui-icon">&#xe615;</i>
                                </button>
                                <a class="layui-btn layui-btn-small" onclick="location.reload()" title="刷新">
                                    <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
                                </a>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body">
                        <button class="layui-btn" onclick="xadmin.open('添加优惠券','{{route("admin_coupon_create")}}')">
                            <i class="layui-icon"></i>添加</button>
                    </div>
                    <div class="layui-card-body layui_overflow_y ">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>优惠券名称</th>
                                <th>优惠(元)/折扣</th>
                                <th>最低消费/面值(元)</th>
                                <th>优惠券号</th>
                                <th>优惠券分类</th>
                                <th>使用类型</th>
                                <th>使用说明</th>
                                <th>领券后有效期(天)</th>
                                <th>领取张数</th>
                                <th>使用张数</th>
                                <th>过期张数</th>
                                <th>状态</th>
                                <th>操作</th></tr>
                            </thead>
                            <tbody>
                            @foreach($data as $key=>$value)
                            <tr>
                                <td>{{ $value['id'] }}</td>
                                <td>{{ $value['name'] }} </td>
                                <td>
                                    @if( $value['pid'] === 1 )
                                        -
                                    @elseif( $value['pid'] === 2 )
                                        {{ $value['price'] }}
                                    @elseif(  $value['pid'] === 3 )
                                        {{ $value['discount_num'] }}
                                    @endif
                                </td>
                                <td>
                                     @if( $value['pid'] === 1 )
                                        {{ $value['price_all'] }}
                                    @else
                                        {{ $value['price_all'] }}
                                    @endif
                                </td>
                                <td>{{ $value['ticket_num'] }}</td>
                                <td>{{ $value['pid_msg'] }}</td>
                                <td>{{ $value['type_msg'] }}</td>
                                <td>{{ $value['content'] }}</td>
                                <td>{{ $value['validity_at'] }}</td>
                                <td>
                                    <a title="领取" onclick="xadmin.open('领取统计','{{route("admin_coupon_list_extend",["id"=>$value["id"]])}}')" href="javascript:;">领取{{ $value['count_ling_count'] }}张</a>
                                </td>
                                <td>
                                    <a title="使用" onclick="xadmin.open('使用统计','{{route("admin_coupon_list_extend",["id"=>$value["id"] , 'status' => 2 ])}}')" href="javascript:;">使用{{ $value['count_yong_count'] }}张</a>
                                </td>
                                <td>
                                    <a title="过期" onclick="xadmin.open('过期统计','{{route("admin_coupon_list_extend",["id"=>$value["id"] , 'status' => 3 ])}}')" href="javascript:;">过期{{ $value['count_guo_count'] }}张</a>
                                </td>
                                <td><input type="checkbox" name="close" data-id="{{$value['id']}}" data-status="{{$value['status']}}" lay-skin="switch" lay-filter="switchTest" @if( $value['status'] == 1 ) checked="" @endif lay-text="启用|禁用"> </td>
                                <td class="td-manage">
                                    <a title="编辑" class="layui-btn" onclick="xadmin.open('编辑优惠券','{{route("admin_coupon_edit",["id"=>$value["id"]])}}')" href="javascript:;">
                                        编辑</a>
                                </td>
                            </tr>
                            @endforeach
                            @if(empty($data))
                                <td colspan="66" align="center">暂无数据</td>
                            @endif
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{$page_link}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection


@section('tab_js')
    <script>
        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

                form.on('switch(switchTest)', function(data){
                    var id = $(this).attr('data-id');
                    var status = 1;
                    if( $(this).attr('data-status') == 1 ){
                        status = 2;
                    }
                    $.ajax({
                        url: js_url('admin-coupon-update'),
                        type: 'post',
                        data: {id:id,status:status,'_token': '{{csrf_token()}}'},
                        dataType: "json",
                        success: function (result) {
                            if (result.state === 0) {
                                layer.msg(result.msg, {time: 500, icon: 6}, function () {
                                    //关闭当前frame
                                    // xadmin.close();
                                    // 可以对父窗口进行刷新
                                    // xadmin.father_reload();
                                });
                            }else if( result.state === 2 ){ 
                                layer.msg(result.msg, {time: 1000, icon: 5}, function () {
                                    location.reload();
                                });
                            } else {
                                layer.msg(result.msg, {time: 2000, icon: 5});
                            }
                        }
                    });
                });

            })
    </script>
@endsection




